package com.sit.library.entity.dao;

import com.sit.library.entity.bean.Account;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AccountMapper {

    @Select("select * from user where Username=#{username}")
    @Results({
            @Result(column = "UserID", property = "id"),
            @Result(column = "Username", property = "name"),
            @Result(column = "Password", property = "password"),
            @Result(column = "Contact", property = "contact"),
            @Result(column = "UserType", property = "role")
    })
    Account findByUsername(String username);

    @Select("select * from user")
    @Results({
            @Result(column = "UserID", property = "id"),
            @Result(column = "Username", property = "name"),
            @Result(column = "Password", property = "password"),
            @Result(column = "Contact", property = "contact"),
            @Result(column = "UserType", property = "role")
    })
    List<Account> findAll();

    @Insert("insert into user (Username, Password, Contact, UserType) " +
            "values (#{name}, #{password}, #{contact}, #{role})")
    int addAccount(Account account);

    @Update("update user set Username=#{name}, Password=#{password}, " +
            "Contact=#{contact}, UserType=#{role} where UserID=#{id}")
    int updateAccount(Account account);

    @Delete("delete from user where UserID=#{accountId}")
    int deleteAccount(int accountId);
}
